home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / wnx1091.lzh / WNXSKEL.C < prev    next >
C/C++ Source or Header  |  1991-10-15  |  5KB  |  216 lines

  1. /*********************************************************************/
  2. /* SAMPLE .WNX APPLICATION SKELETON */
  3. /*    portions borrowed from: */
  4. /*    started 5/28/85 R.Z.   Copyright ATARI Corp. 1985 */
  5. /*********************************************************************/
  6. /*********************************************************************/
  7. /* INCLUDE FILES */
  8. /*********************************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <obdefs.h>
  12. #include <gemdefs.h>
  13. #include <osbind.h>
  14. #include <xesblk.h>
  15. #include <xesdefs.h>
  16. /*********************************************************************/
  17. /* DEFINES */
  18. /*********************************************************************/
  19. #define LASERC
  20. #define TRUE 1
  21. #define FALSE 0
  22.  
  23. #define    ACCNAME    "Flip's .ACC"
  24.  
  25. #define WI_KIND        (SIZER|MOVER|FULLER|CLOSER|NAME)
  26.  
  27. #define NO_WINDOW (-1)
  28.  
  29. #define MIN_WIDTH  (2*gl_wbox)
  30. #define MIN_HEIGHT (3*gl_hbox)
  31.  
  32. /*********************************************************************/
  33. /* EXTERNALS                                    */
  34. /*********************************************************************/
  35.  
  36. extern int    gl_apid,_app,errno;
  37. extern long    base,stksize,stack;
  38.  
  39. extern struct __c {
  40.     int *cb_pcontrol;
  41.     int *cb_pglobal;
  42.     int *cb_pintin;
  43.     int *cb_pintout;
  44.     long *cb_padrin;
  45.     long *cb_padrout;
  46. } _c, *_ad_c;
  47.  
  48. extern int control[], global[]; 
  49. extern int_in[], int_out[];
  50. extern long addr_in[], addr_out[];
  51.  
  52. /*********************************************************************/
  53. /* GLOBAL VARIABLES                                */
  54. /*********************************************************************/
  55.  
  56. int    gl_hchar;
  57. int    gl_wchar;
  58. int    gl_wbox;
  59. int    gl_hbox;    /* system sizes */
  60.  
  61. int     phys_handle;    /* physical workstation handle */
  62. int     handle;        /* virtual workstation handle */
  63. int        wi_handle;    /* window handle */
  64. int        top_window;    /* handle of topped window */
  65.  
  66. int    xdesk,ydesk,hdesk,wdesk;
  67. int    xold,yold,hold,wold;
  68. int    xwork,ywork,hwork,wwork;    /* desktop and work areas */
  69.  
  70. int    msgbuff[8];    /* event message buffer */
  71. int    keycode;    /* keycode returned by event-keyboard */
  72. int    mx,my;        /* mouse x and y pos. */
  73. int    butdown;    /* button state tested for, UP/DOWN */
  74. int    ret;        /* dummy return variable */
  75.  
  76. int    hidden;        /* current state of cursor */
  77.  
  78. int    fulled;        /* current state of window */
  79.  
  80. int    contrl[12];
  81. int    intin[128];
  82. int    ptsin[128];
  83. int    intout[128];
  84. int    ptsout[128];    /* storage wasted for idiotic bindings */
  85.  
  86. int work_in[11];    /* Input to GSX parameter array */
  87. int work_out[57];    /* Output from GSX parameter array */
  88. int pxyarray[10];    /* input point array */
  89.  
  90. int    menu_id;
  91.  
  92. xesparmblk    xparmblk;
  93.  
  94. /****************************************************************/
  95. /* open virtual workstation                    */
  96. /****************************************************************/
  97. open_vwork()
  98. {
  99. int i;
  100.     for(i=0;i<10;work_in[i++]=1);
  101.     work_in[10]=2;
  102.     handle=phys_handle;
  103.     v_opnvwk(work_in,&handle,work_out);
  104. }
  105.  
  106. /*    This is some stuff common to both .ACC and .PRG executables
  107.         which I do whenever they start up...                                            */
  108. void prg_acc_startup()
  109. {
  110.         appl_init();
  111.         phys_handle=graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
  112.         open_vwork();
  113.  
  114.         wi_handle=NO_WINDOW;
  115.         hidden=FALSE;
  116.         fulled=FALSE;
  117.         butdown=TRUE;
  118. }    
  119.  
  120. /****************************************************************/
  121. /* dispatches all accessory tasks                */
  122. /****************************************************************/
  123. multi()
  124. {
  125.     int event;
  126.  
  127.       while (TRUE) {
  128.   
  129.           /*    currently only messages... could change this to an
  130.                   evnt_mesag call, but I like to keep it open... */
  131.                 event = evnt_multi(MU_MESAG,
  132.                 1,1,1,
  133.                 0,0,0,0,0,
  134.                 0,0,0,0,0,
  135.                 msgbuff,0,0,&mx,&my,&ret,&ret,&keycode,&ret);
  136.  
  137.                 switch(msgbuff[0]){
  138.                     case    AC_OPEN:
  139.                                 program();
  140.                                 break;
  141.                 }
  142.             }
  143. }
  144.  
  145. program()
  146. {
  147. /*    code for program's "guts" goes here... this is only called if
  148.         we're an .ACC or .PRG.  A .WNX has to call this itself.            */
  149. }
  150. /****************************************************************/
  151. /*        Accessory Init. Until First Event_Multi        */
  152. /****************************************************************/
  153. main()
  154. {
  155.     switch(_app)
  156.     {
  157.         case    -1:
  158.             {
  159.                 /*    WNX    */
  160.         
  161.                 xes_init(&xparmblk);
  162.                 
  163.                 /*    A .WNX doesn't have the variable __c, which is
  164.                         its AES parameter block, fixed up during an
  165.                         appl_init, so I have to do it myself.    */
  166.             
  167.                 _c.cb_pcontrol=control;
  168.                 _c.cb_pglobal=global;
  169.                 _c.cb_pintin=int_in;
  170.                 _c.cb_pintout=int_out;
  171.                 _c.cb_padrin=addr_in;
  172.                 _c.cb_padrout=addr_out;
  173.             
  174.                 _ad_c=&_c;
  175.  
  176.                 xes_genv(&xparmblk);
  177.                 xes_pwindow(&xparmblk);
  178.  
  179.                 /* Fixes the WNX' i.d. name field */
  180.                 strcpy(xparmblk.WNX_idname,"I AM A WNX");
  181.  
  182.                 xes_submit(&xparmblk);
  183.                 break;
  184.             }
  185.  
  186. #ifdef LASERC
  187. /*    This is needed since LASER C doesn't make A0 = 0, but does
  188.     make p_parent null.  I just make it so if LASERC == TRUE,
  189.     we know this is being run from the LASER C shell, and so
  190.     it will be a program...                                    */
  191.         default:
  192.         {
  193.             _app=1;
  194.             prg_acc_startup();
  195.             program();
  196.         }
  197. #else
  198.         case    1:
  199.         {
  200.         /*    PROGRAM    */
  201.             prg_acc_startup();
  202.             program();
  203.             break;
  204.         }
  205.         case    0:
  206.         {
  207.         /* ACCESSORY */
  208.             prg_acc_startup();
  209.             menu_id=menu_register(gl_apid,ACCNAME);
  210.             multi();
  211.             break;
  212.         }
  213. #endif    
  214.     }
  215. }
  216.